#!/usr/bin/env ruby
#-*- coding:utf-8 -*-

require "net/imap"

if caller.length == 0 then
  cli = Net::IMAP.new 'imap.ym.163.com'
  cli.login 'user', 'pswd'

  mail_boxes = cli.list "", "*"

  # 垃圾邮件
  cli.select mail_boxes[4].name

  mails = cli.search ['ALL']

  mails.each do |msg_id|
    msg = cli.fetch(msg_id, "(ENVELOPE BODY[TEXT])")[0]
    envelope = msg.attr['ENVELOPE']
    body = msg.attr['BODY[TEXT]']
  end

end
